const path = require('path') // 添加 path 模块
const resolve = require('@rollup/plugin-node-resolve')
const commonjs = require('@rollup/plugin-commonjs')
const deleteFile = require('rollup-plugin-delete')
const json = require('@rollup/plugin-json')
const copy = require('rollup-plugin-copy')
const alias = require('@rollup/plugin-alias') // 新增别名插件
module.exports = {
  input: './src/app.js', // 输入文件
  output: {
    dir: 'dist', // 输出文件
    format: 'cjs', // 打包格式,
    exports: 'auto', // 或者 'default'
    chunkFileNames: '[name]-[hash].js',
    entryFileNames: '[name].js',
  },
  plugins: [
    deleteFile({ targets: 'dist/*' }), // 只删除 dist 文件夹中的内容
    resolve({
      preferBuiltins: true,
    }), // 解析导入的第三方模块
    commonjs(), // 将CommonJS模块转换为ES模块
    json(),
    copy({
      targets: [
        { src: 'system.config.js', dest: 'dist' }, // 复制 system.config.js 到 dist 目录
      ],
    }),
    alias({
      // 新增别名配置
      entries: [
        {
          find: '@',
          replacement: path.resolve(__dirname, 'src'),
        },
      ],
    }),
  ],
  external: ['fastify', 'winston'],
}
